package com.clusterswisdom.horn.api.tmall.action.item;

import java.sql.Connection;
import java.sql.PreparedStatement;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSONObject;
import com.clusterswisdom.horn.api.db.DbUtil;
import com.clusterswisdom.horn.api.ioc.HornAction;
import com.clusterswisdom.horn.api.ioc.HornResponse;
import com.clusterswisdom.horn.api.ioc.api.ApiConfig;
import com.clusterswisdom.horn.api.tmall.action.AbstractTmallAction;

public class UpdateSomeItemAction extends AbstractTmallAction implements HornAction{
	private Logger log = LoggerFactory.getLogger(UpdateSomeItemAction.class);
	@Override
	public HornResponse execute(ApiConfig config, JSONObject param)
			throws Exception {
		String cai = param.getString("cai");
		int num = param.getInteger("num");
		param.put("outer_id", cai);
			
		Connection con = DbUtil.getUtil().getConnection();
		try{
			String sql = "update itemsforsetting set `num` = ? where cai = ?";
			PreparedStatement ps = con.prepareStatement(sql);
			log.debug("cai :"+ cai + " num :"+ num);
			ps.setInt(1, num);
			ps.setString(2, cai);
			ps.execute();
			ps.close();
		}catch(Exception e){
			e.printStackTrace();
			DbUtil.getUtil().rollback();
			return new HornResponse(false, "失败");
		}finally{
			DbUtil.getUtil().commit();
		}
		return new HornResponse(true, "成功");
	}
}
